<template>
	<view>
		<view v-if="pd.curProcessConfig && pd.curProcessConfig.isNeedCheck">
			<view class="flrc bca01 pos-r mar1" v-if="curTag !== null" >
				<view class="flex3 padl1">{{curTag.code}}{{curTag.name}}</view>
				<view class="fs14 flex2 padtb1 bcf">
					<input adjust-position focus placeholder="请输入" confirm-type="next" @blur="reCountCheckGroup" 
					class="tac bg-white lh2 fs20" placeholder-class="c12 fs12" type="number" v-model.number="curTag.value" />
				</view>
			</view>
			<view v-else class="fs14 c12 op5 tac padtb2 mart1">
				点击下面的标签开始填写数量
			</view>
			
			<view class="bdtda bdbda">
				<stab v-model="curTagTab" :names="pd.groupsNames" :key="groupTagKey"></stab>
			</view>
			<view v-if="pd.curProcessConfig !== null">
				<view class="" v-if="index == curTagTab" v-for="(group,index) in pd.checkGroups">
					<scroll-view scroll-y>
						<view class="tagBox flex-r flex-start flex-wrap">
							<view class="tagItem flcc pad1" v-for="(tag,index) in group.tags">
								<view :class="{'bg-green':tag.selected}" @tap="addTag(tag)" class="pos-r cu-btn w100">
									{{tag.code}}.{{tag.name}}
									<text class="marlr1" v-if="tag.selected">( {{tag.value}} )</text>
									<ripple></ripple>
								</view>
							</view>
							
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
		<view  v-else class="fs14 c12 op5 tac padtb2 mart1">
				非检验工序，无需填写
		</view>
	</view>
</template>

<script>
import log from '../../../assets/js/log';
import PublicData from './PublicData'
	export default {
		props:{
			flow:0,
		},
		data() {
			return {
				pd:PublicData,
				lastProcess:null,
				lastProcessId:0,
				lastProcessCount:0,
				curTagTab:0,
				groupTagKey:"",
				groupsNames:[],
				checkGroups:[],
				curTag:null,
			}
		},
		mounted() {
		},
		methods: {
			addTag(tag){
				tag.selected = !tag.selected
				if (tag.selected){
					this.curTag = tag
				}else{
					this.curTag = null
					tag.value == null
					this.reCountCheckGroup()
				}
			},
			removeTag(tag){
				tag.selected = false
				tag.value = null
				this.reCountCheckGroup()
			},
			reCountCheckGroup(){
				this.pd.checkGroups.forEach((group,index)=>{
					let total = 0
					group.tags.map(tag=>{
						if(tag.selected){
							if (tag.value *1 == 0){
								tag.selected = false
							}
							total+=tag.value
						}else{
							tag.value = null
						}
					})
					group.total = total
					this.pd.groupsNames[index] = `${group.name}(${total})`
					switch (group.id){
						case 2:
						this.pd.numX = total
						break
						case 3:
						this.pd.numH = total
						break
						case 4:
						this.pd.numF = total
						break
					}
				})
				this.groupTagKey = Math.random()
				this.curTag = null
				this.pd.rebuildNums()
			}
		}
	}
</script>

<style scoped>
.tagBox{
	height: 70vw;
}
.tagItem{
	width: 50%;
}
.tagItemInput{
	width: 30vw;
}
</style>
